﻿using System;
using System.Data.SqlClient;
using System.Web.UI;
using UDS.Components;

namespace UDS.SubModule.Schedule
{
    /// <summary>
    /// TaskComment 的摘要说明。
    /// </summary>
    public partial class TaskCommentPage : Page
    {
        private void Page_Load(object sender, EventArgs e)
        {
            if (!Page.IsPostBack)
            {
                string Username = SiteContext.Current.UserName;
                string TaskID = (Request.QueryString["TaskID"] != null) ? Request.QueryString["TaskID"] : "0";
                string Action = (Request.QueryString["Action"] != null) ? Request.QueryString["Action"] : "0";
                string CID = (Request.QueryString["CID"] != null) ? Request.QueryString["CID"] : "0";
                bool delflag = false;
                var tsk = new Task();
                if (Action == "1")
                {
                    try
                    {
                        tsk.DeleteTaskComment(Int32.Parse(CID));
                        Response.Redirect("TaskComment.aspx?TaskID=" + TaskID);
                    }
                    catch (Exception ex)
                    {
                        Logger.Log(ex.ToString());
                        Server.Transfer("../Error.aspx");
                    }
                }

                TaskClass tc = tsk.GetTaskDetail(Int32.Parse(TaskID));
                if (tc.ArrangedBy == Username)
                {
                    delflag = true;
                }
                SqlDataReader dataReader = tsk.GetTaskComment(Int32.Parse(TaskID));
                lt.Text = "<table class=gbtext style='BORDER-COLLAPSE: collapse'>";
                while (dataReader.Read())
                {
                    lt.Text += "<tr><td>" + dataReader["Comment"] + "<br>------------<br><font color=red>" + Components.Staff.GetRealNameByUsername(dataReader["Username"].ToString()) + "  ";
                    lt.Text += (delflag) ? "<a href='TaskComment.aspx?Action=1&TaskID=" + TaskID + "&CID=" + dataReader["ID"] + "'>删除</a>" : "";
                    lt.Text += "  </font><br><bR>";
                    lt.Text += "</td></tr>";
                }
                lt.Text += "</table>";
                dataReader.Close();
            }
        }

        #region Web Form Designer generated code

        protected override void OnInit(EventArgs e)
        {
            //
            // CODEGEN：该调用是 ASP.NET Web 窗体设计器所必需的。
            //
            InitializeComponent();
            base.OnInit(e);
        }

        /// <summary>
        /// 设计器支持所需的方法 - 不要使用代码编辑器修改
        /// 此方法的内容。
        /// </summary>
        private void InitializeComponent()
        {
            this.Load += new System.EventHandler(this.Page_Load);
        }

        #endregion
    }
}